/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MDI2.java
 *
 * Created on 25/10/2012, 20:36:43
 */

package br.com.fatecpg.mdi;


import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import projeto.Animal;
import projeto.Conhecimento_Transporte;
import projeto.Despesa;
import projeto.Login;
import projeto.Motorista;
import projeto.Tipo_Animal;
import projeto.Tipo_Despesa;
import projeto.Tipo_Veiculo;
import projeto.Usuario;
import projeto.Veiculo;
import projeto.classes.ModeloUsuario;
import projeto.fCliente;

/**
 *
 * @author Fatec
 */
public class MDI2 extends javax.swing.JFrame {

    private projeto.classes.ModeloUsuario usuarioLogado;

    public ModeloUsuario getUsuarioLogado() {
        return usuarioLogado;
    }

    public void setUsuarioLogado(ModeloUsuario usuarioLogado) {
        this.usuarioLogado = usuarioLogado;
    }
    
    Login log;
    
    //getters dos controles do mdi
    public JMenu getMenuPrincipal() {
        return menuPrincipal;
    }

    public JDesktopPane getDesktopPane() {
        return desktopPane;
    }

    public JMenuItem getDeslogarMenuItem() {
        return deslogarMenuItem;
    }

    public JMenuItem getLogarMenuItem() {
        return logarMenuItem;
    }

    public JMenu getMenuLogin() {
        return menuLogin;
    }

    public JLabel getLblUsuarioLogado() {
        return lblUsuarioLogado;
    }

    public JMenuItem getUsuarioMenuItem() {
        return usuarioMenuItem;
    }

    public JMenuItem getTipo_AnimalMenuItem() {
        return tipo_AnimalMenuItem;
    }

    public JMenuItem getTipo_DespesaMenuItem() {
        return tipo_DespesaMenuItem;
    }

    public JMenuItem getTipo_VeiculoMenuItem() {
        return tipo_VeiculoMenuItem;
    }
    
    

    
    /** Creates new form MDI2 */
    public MDI2() {
        initComponents();
        this.setTitle("Entrega Gado");
        //maximiza o mdi
        this.setExtendedState(JFrame.MAXIMIZED_BOTH); 
        
        this.deslogarMenuItem.setEnabled(false);
        
        log = new Login(this);
        desktopPane.add(log);
        log.setVisible(true);
        
        this.menuPrincipal.setEnabled(false);
    }



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        desktopPane = new javax.swing.JDesktopPane();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lblUsuarioLogado = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        menuLogin = new javax.swing.JMenu();
        logarMenuItem = new javax.swing.JMenuItem();
        deslogarMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        sairMenuItem = new javax.swing.JMenuItem();
        menuPrincipal = new javax.swing.JMenu();
        clienteMenuItem = new javax.swing.JMenuItem();
        animalMenuItem = new javax.swing.JMenuItem();
        conhecimento_TransporteAsMenuItem = new javax.swing.JMenuItem();
        despesaMenuItem = new javax.swing.JMenuItem();
        motoristaMenuItem = new javax.swing.JMenuItem();
        tipo_AnimalMenuItem = new javax.swing.JMenuItem();
        tipo_DespesaMenuItem = new javax.swing.JMenuItem();
        tipo_VeiculoMenuItem = new javax.swing.JMenuItem();
        veiculoMenuItem5 = new javax.swing.JMenuItem();
        usuarioMenuItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        sobreMenuItem = new javax.swing.JMenuItem();

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(51, 51, 51));
        jLabel3.setText("SISTEMA DE TRANSPORTE");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 51, 51));
        jLabel4.setText("SISTEMA DE TRANSPORTE");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        desktopPane.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                desktopPaneComponentResized(evt);
            }
            public void componentShown(java.awt.event.ComponentEvent evt) {
                desktopPaneComponentShown(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 51, 51));
        jLabel1.setText("ENTREGA GADO");
        jLabel1.setBounds(160, 270, 210, 80);
        desktopPane.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setForeground(new java.awt.Color(255, 0, 0));
        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/projeto/gado.jpg"))); // NOI18N
        jLabel2.setBounds(20, 100, 350, 250);
        desktopPane.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 51, 51));
        jLabel5.setText("SISTEMA DE TRANSPORTE");
        jLabel5.setBounds(30, 50, 350, 80);
        desktopPane.add(jLabel5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lblUsuarioLogado.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lblUsuarioLogado.setForeground(new java.awt.Color(51, 255, 51));
        lblUsuarioLogado.setText("Usuário logado: ");
        lblUsuarioLogado.setBounds(20, 10, 340, 20);
        desktopPane.add(lblUsuarioLogado, javax.swing.JLayeredPane.DEFAULT_LAYER);

        menuLogin.setText("Acessar");

        logarMenuItem.setText("Logar");
        logarMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logarMenuItemActionPerformed(evt);
            }
        });
        menuLogin.add(logarMenuItem);

        deslogarMenuItem.setText("Deslogar");
        deslogarMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deslogarMenuItemActionPerformed(evt);
            }
        });
        menuLogin.add(deslogarMenuItem);
        menuLogin.add(jSeparator1);

        sairMenuItem.setText("Sair");
        sairMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sairMenuItemActionPerformed(evt);
            }
        });
        menuLogin.add(sairMenuItem);

        menuBar.add(menuLogin);

        menuPrincipal.setText("Menu Principal");
        menuPrincipal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuPrincipalActionPerformed(evt);
            }
        });

        clienteMenuItem.setText("Cliente");
        clienteMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clienteMenuItemActionPerformed(evt);
            }
        });
        menuPrincipal.add(clienteMenuItem);

        animalMenuItem.setText("Animal");
        animalMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                animalMenuItemActionPerformed(evt);
            }
        });
        menuPrincipal.add(animalMenuItem);

        conhecimento_TransporteAsMenuItem.setText("Ordem de Transporte");
        conhecimento_TransporteAsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                conhecimento_TransporteAsMenuItemActionPerformed(evt);
            }
        });
        menuPrincipal.add(conhecimento_TransporteAsMenuItem);

        despesaMenuItem.setText("Despesa");
        despesaMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                despesaMenuItemActionPerformed(evt);
            }
        });
        menuPrincipal.add(despesaMenuItem);

        motoristaMenuItem.setText("Motorista");
        motoristaMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                motoristaMenuItemActionPerformed(evt);
            }
        });
        menuPrincipal.add(motoristaMenuItem);

        tipo_AnimalMenuItem.setText("Tipo de Animal");
        tipo_AnimalMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tipo_AnimalMenuItemActionPerformed(evt);
            }
        });
        menuPrincipal.add(tipo_AnimalMenuItem);

        tipo_DespesaMenuItem.setText("Tipo de Despesa");
        tipo_DespesaMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tipo_DespesaMenuItemActionPerformed(evt);
            }
        });
        menuPrincipal.add(tipo_DespesaMenuItem);

        tipo_VeiculoMenuItem.setText("Tipo de Veiculo");
        tipo_VeiculoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tipo_VeiculoMenuItemActionPerformed(evt);
            }
        });
        menuPrincipal.add(tipo_VeiculoMenuItem);

        veiculoMenuItem5.setText("Veiculo");
        veiculoMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                veiculoMenuItem5ActionPerformed(evt);
            }
        });
        menuPrincipal.add(veiculoMenuItem5);

        usuarioMenuItem.setText("Usuário");
        usuarioMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                usuarioMenuItemActionPerformed(evt);
            }
        });
        menuPrincipal.add(usuarioMenuItem);

        menuBar.add(menuPrincipal);

        editMenu.setText("Sobre");
        editMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editMenuActionPerformed(evt);
            }
        });

        sobreMenuItem.setText("Sobre");
        sobreMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sobreMenuItemActionPerformed(evt);
            }
        });
        editMenu.add(sobreMenuItem);

        menuBar.add(editMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void despesaMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_despesaMenuItemActionPerformed
        Despesa d = new Despesa(getUsuarioLogado(), this);
        desktopPane.add(d);
        d.setVisible(true);
        d.setResizable(true);
        d.setMaximizable(true);
        d.setClosable(true);
    }//GEN-LAST:event_despesaMenuItemActionPerformed

    private void motoristaMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_motoristaMenuItemActionPerformed
        Motorista e = new Motorista(getUsuarioLogado(), this);
        desktopPane.add(e);
        e.setVisible(true);
        e.setResizable(true);
        e.setMaximizable(true);
        e.setClosable(true);
    }//GEN-LAST:event_motoristaMenuItemActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened

    }//GEN-LAST:event_formWindowOpened

    private void menuPrincipalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuPrincipalActionPerformed
       
    }//GEN-LAST:event_menuPrincipalActionPerformed

    private void animalMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_animalMenuItemActionPerformed
        Animal a = new Animal(getUsuarioLogado(), this);
        desktopPane.add(a);
        a.setVisible(true);
        a.setResizable(true);
        a.setMaximizable(true);
        a.setClosable(true);
    }//GEN-LAST:event_animalMenuItemActionPerformed

    private void clienteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clienteMenuItemActionPerformed
        fCliente c = new fCliente(this, getUsuarioLogado());
        desktopPane.add(c);
        c.setVisible(true);
        c.setResizable(true);
        c.setMaximizable(true);
        c.setClosable(true);

    }//GEN-LAST:event_clienteMenuItemActionPerformed

    private void conhecimento_TransporteAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_conhecimento_TransporteAsMenuItemActionPerformed

        Conhecimento_Transporte c = new Conhecimento_Transporte(getUsuarioLogado(), this);
        desktopPane.add(c);
        c.setVisible(true);
        c.setResizable(true);
        c.setMaximizable(true);
        c.setClosable(true);
    }//GEN-LAST:event_conhecimento_TransporteAsMenuItemActionPerformed

    private void tipo_AnimalMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tipo_AnimalMenuItemActionPerformed
        Tipo_Animal f = new Tipo_Animal();
        desktopPane.add(f);
        f.setVisible(true);
        f.setResizable(true);
        f.setMaximizable(true);
        f.setClosable(true);
    }//GEN-LAST:event_tipo_AnimalMenuItemActionPerformed

    private void tipo_DespesaMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tipo_DespesaMenuItemActionPerformed
        Tipo_Despesa g = new Tipo_Despesa();
        desktopPane.add(g);
        g.setVisible(true);
        g.setResizable(true);
        g.setMaximizable(true);
        g.setClosable(true);
    }//GEN-LAST:event_tipo_DespesaMenuItemActionPerformed

    private void tipo_VeiculoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tipo_VeiculoMenuItemActionPerformed
        Tipo_Veiculo h = new Tipo_Veiculo();
        desktopPane.add(h);
        h.setVisible(true);
        h.setResizable(true);
        h.setMaximizable(true);
        h.setClosable(true);
    }//GEN-LAST:event_tipo_VeiculoMenuItemActionPerformed

    private void veiculoMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_veiculoMenuItem5ActionPerformed
        Veiculo i = new Veiculo(getUsuarioLogado(), this);
        desktopPane.add(i);
        i.setVisible(true);
        i.setResizable(true);
        i.setMaximizable(true);
        i.setClosable(true);
    }//GEN-LAST:event_veiculoMenuItem5ActionPerformed

    private void editMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editMenuActionPerformed
        
    }//GEN-LAST:event_editMenuActionPerformed

    private void sobreMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sobreMenuItemActionPerformed
        Sobre dialog = new Sobre(this,true);
        dialog.setPosicao(this);
        dialog.setVisible(true);
    }//GEN-LAST:event_sobreMenuItemActionPerformed

    private void desktopPaneComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_desktopPaneComponentShown
        
    }//GEN-LAST:event_desktopPaneComponentShown

    private void desktopPaneComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_desktopPaneComponentResized
        
        //tela de login é centralizada logo apos o mdi ser maximizado
        log.setPosicao();
        
    }//GEN-LAST:event_desktopPaneComponentResized

    private void logarMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logarMenuItemActionPerformed
        log = new Login(this);
        desktopPane.add(log);
        log.setVisible(true);
        log.setPosicao();
    }//GEN-LAST:event_logarMenuItemActionPerformed

    private void deslogarMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deslogarMenuItemActionPerformed
        //apenas seta o objeto de usuario como null
        lblUsuarioLogado.setText("Usuário logado: --");
        menuPrincipal.setEnabled(false);
        logarMenuItem.setEnabled(true);
        deslogarMenuItem.setEnabled(false);
        usuarioLogado = null;
    }//GEN-LAST:event_deslogarMenuItemActionPerformed

    private void sairMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sairMenuItemActionPerformed

        if (JOptionPane.showConfirmDialog(this, "Tem certeza que deseja sair?", "Entrega Gado", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) {
            this.dispose();
        }
    }//GEN-LAST:event_sairMenuItemActionPerformed

    private void usuarioMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_usuarioMenuItemActionPerformed
        Usuario u = new Usuario();
        desktopPane.add(u);
        u.setVisible(true);
        u.setResizable(true);
        u.setMaximizable(true);
        u.setClosable(true);
    }//GEN-LAST:event_usuarioMenuItemActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MDI2().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem animalMenuItem;
    private javax.swing.JMenuItem clienteMenuItem;
    private javax.swing.JMenuItem conhecimento_TransporteAsMenuItem;
    private javax.swing.JDesktopPane desktopPane;
    private javax.swing.JMenuItem deslogarMenuItem;
    private javax.swing.JMenuItem despesaMenuItem;
    private javax.swing.JMenu editMenu;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JLabel lblUsuarioLogado;
    private javax.swing.JMenuItem logarMenuItem;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenu menuLogin;
    private javax.swing.JMenu menuPrincipal;
    private javax.swing.JMenuItem motoristaMenuItem;
    private javax.swing.JMenuItem sairMenuItem;
    private javax.swing.JMenuItem sobreMenuItem;
    private javax.swing.JMenuItem tipo_AnimalMenuItem;
    private javax.swing.JMenuItem tipo_DespesaMenuItem;
    private javax.swing.JMenuItem tipo_VeiculoMenuItem;
    private javax.swing.JMenuItem usuarioMenuItem;
    private javax.swing.JMenuItem veiculoMenuItem5;
    // End of variables declaration//GEN-END:variables

}
